package com.nbicc.util;

/**
 * 用于封装 json数据
 */
public class JsonData {
    private int code;
    private String msg;
    private Object Data;

    public JsonData() {}

    public JsonData(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        Data = data;
    }

    /**
     * 返回成功
     * @param data
     * @return
     */
    public JsonData buildSuccess(Object data){
        return new JsonData(0,"ok",data);
    }
    public JsonData buildSuccess() {
        return new JsonData(0,"ok",null);
    }
    /**
     * 返回异常
     * @return
     */
    public JsonData buildFailure(){
        return new JsonData(-1,"error",null);
    }

    public JsonData buildFailure(String msg){
        return new JsonData(-1,msg,null);
    }

    public JsonData buildFailure(Integer code, String msg) {
        return new JsonData(code,msg,null);
    }



    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return Data;
    }

    public void setData(Object data) {
        Data = data;
    }
}
